﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CopySniffer.UI.Core.Controlers
{
    public abstract class BaseControler<TView, TControler> : IControler
        where TView : IView<TControler>
        where TControler : BaseControler<TView, TControler>
    {
        protected BaseControler()
        {
            View = ViewFactories.Default.CreateView<TView, TControler>();
            // TODO: this whole generics-based design looks complex. Check for an alternative.
            View.Controler = (TControler)this;
        }

        protected void DoStart()
        {
            View.Show();
        }

        public TView View { get; private set; }

        public virtual bool AllowClose()
        {
            return true;
        }

        public virtual void Close()
        {
            OnClosed();
        }

        private void OnClosed()
        {
            if (Closed != null)
            {
                Closed(this, EventArgs.Empty);
            }
        }

        public event EventHandler Closed;
    }
}
